var href = decodeURI(location.href)
console.log(href);
function getQueryString(url){
    //通过？分割数组
    let cs = url.split("?")[1]
    console.log(cs);

    //判断如果没有参数，返回null
    if(!cs){
        return null;
    }
    
    //针对所有参数分割成数组
    let csarr = cs.split("&")
    console.log(csarr);

    //定义一个接受结果的对象
    let csobj = {};
    //遍历所有的参数数组，通过=将key和value分割存入对象
    csarr.forEach(item => {
        csobj[item.split("=")[0]] = item.split("=")[1];
    });
    console.log(csobj);
    return csobj;
}
var cs = getQueryString(href);
console.log(cs);

var main = document.querySelector("main")
fetch("http://chst.vip:1234/api/getmoneyctrlproduct?productid="+cs.productid)
.then(data=>{
    return data.json();
})
.then(res=>{
    console.log(res);
    console.log(res.result);
    console.log(res.result[0].productName);
    let regExp = /(?<=imgurl=)[^'"]*/;
    var img = regExp.exec(res.result[0].productImg2)[0]
    let ele = "";
    ele += `<main>
                <div class="title">
                    <h4>${res.result[0].productName}</h4>
                </div>
                <div class="other">
                    <span>${res.result[0].productFrom}| ${res.result[0].productTime}</span>
                    <i>${res.result[0].productTips}</i>
                </div>
                <div class="xiangqing">
                    <img src="${img}" alt="">
                    <p>${res.result[0].productInfo}${res.result[0].productInfo1}</p>
                </div>
                <div class="bigpic">
                    <img src="${img}" alt="">
                </div>
                <div class="city">
                    <ul>${res.result[0].productCity}</ul>
                </div>
                <div class="buy">
                    <a href="#">前往购买</a>
                    <img src="http://chst.vip:8081/for-stu/wfzh/images/mmbweixin2.png" alt="">
                </div>
                <div class="ma">
                    ${res.result[0].productComment}
                </div>
                <div class="textarea">
                    <div class="empty">
                        <a href="#">提交评论</a>
                    </div>
                </div>
                <div class="comment">
                    
                </div>
            </main>`
    main.innerHTML = ele;
})
